package com.dhwl.hsh.driver.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.dhwl.hsh.driver.R;
import com.dhwl.hsh.driver.ui.activity.CommentOrderActivity;
import com.dhwl.hsh.driver.ui.activity.OrderDetailActivity;
import com.dhwl.hsh.lib.bean.resp.OrderListResponse;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 订单列表适配器
 *
 * @author Derek.Kidd
 * @time 2016/4/23 17:06
 */
public class OrderListAdapter extends BaseAdapter<OrderListResponse> {


    public OrderListAdapter(Context context, List<OrderListResponse> list) {
        super(context, list);
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = inflate(R.layout.item_layout_order, null);
            viewHolder = new ViewHolder(convertView);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
//        final OrderListResp item = getList().get(position);


        convertView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, OrderDetailActivity.class);
//                intent.putExtra("order_id", item.getOrder_id());
                context.startActivity(intent);
            }
        });
//        viewHolder.orderTime.setText(item.getOrder_time());
//        viewHolder.orderStatus.setText(StringUtils.getOrderStatus(item.getOrder_status(),
//            item.getPay_status(),
//            item.getShipping_status()));
//        viewHolder.goodsTotalCount.setText(context.getString(R.string.order_goods_total_count, item.getNumber()));
//        viewHolder.orderTotalPrice.setText(context.getString(R.string.order_total_price,
//            item.getTotal_fee(),
//            item.getShipping_fee()));
//        viewHolder.btnOrderOperate.setVisibility(View.GONE);
//        //未付款
//        if (("0".equals(item.getOrder_status()) || "1".equals(item.getOrder_status()))
//            && "0".equals(item.getShipping_status()) && "0".equals(item.getPay_status()))
//        {
//            //货到付款
//            if ("3".equals(item.getPayment().getPay_id()))
//            {
//                viewHolder.btnOrderOperate.setVisibility(View.GONE);
//            }
//            else
//            {
//                viewHolder.btnOrderOperate.setVisibility(View.VISIBLE);
//            }
//            viewHolder.btnOrderOperate.setText(R.string.order_status_go_pay);
//            viewHolder.btnOrderOperate.setOnClickListener(new OnClickListener()
//            {
//
//                @Override
//                public void onClick(View v)
//                {
//                    Intent intent = new Intent(context, PayCenterActivity.class);
//                    intent.putExtra("amount", item.getTotal_fee());
//                    intent.putExtra("order_sn", item.getOrder_sn());
//                    intent.putExtra("address", item.getAddress());
//                    context.startActivity(intent);
//                }
//            });
//        }
//        //待发货
//        if ("1".equals(item.getOrder_status())
//            && ("0".equals(item.getShipping_status()) || "3".equals(item.getShipping_status()))
//            && "2".equals(item.getPay_status()))
//        {
//
//        }
//        //待收货
//        if (("1".equals(item.getOrder_status()) || "5".equals(item.getOrder_status()))
//            && "1".equals(item.getShipping_status()) && "2".equals(item.getPay_status()))
//        {
//            viewHolder.btnOrderOperate.setVisibility(View.VISIBLE);
//            viewHolder.btnOrderOperate.setText(R.string.order_confirm_receiving);
//            viewHolder.btnOrderOperate.setOnClickListener(new OnClickListener()
//            {
//
//                @Override
//                public void onClick(View v)
//                {
//                    showConfirmDialog(position);
//                }
//            });
//
//        }

        return convertView;
    }

    @OnClick(R.id.btn_comment_order)
    public void onCommentClick(View view) {
        Intent intent = new Intent();
        intent.setClass(context, CommentOrderActivity.class);
        context.startActivity(intent);
    }


    class ViewHolder {
        @Bind(R.id.tv_order_type)
        TextView tvOrderType;
        @Bind(R.id.tv_merchant_name)
        TextView tvDriverName;
        @Bind(R.id.tv_merchant_rate)
        TextView tvDriverRate;
        @Bind(R.id.tv_order_status)
        TextView tvOrderStatus;
        @Bind(R.id.tv_task_start_add)
        TextView tvOrderStartAdd;
        @Bind(R.id.tv_order_end_add)
        TextView tvOrderEndAdd;
        @Bind(R.id.tv_order_start_time)
        TextView tvOrderStartTime;
        @Bind(R.id.tv_order_total_price)
        TextView tvOrderTotalPrice;
        @Bind(R.id.btn_for_pay)
        Button btnForPay;
        @Bind(R.id.btn_tel_driver)
        Button btnTelDriver;
        @Bind(R.id.btn_verify_order)
        Button btnVerifyOrder;
        @Bind(R.id.btn_comment_order)
        Button btnCommentOrder;
        @Bind(R.id.btn_fix_order)
        Button btnFixOrder;
        @Bind(R.id.btn_cancel_order)
        Button btnCancelOrder;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
